﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Common;
using TCPIPControl.StructHelper;
using System.Windows.Forms.DataVisualization.Charting;

namespace VibrationTest.OnLineChart
{
    public partial class frmHistogram : Form
    {
        public frmHistogram()
        {
            InitializeComponent();
        }
        public Common.DBOper.Cls_Channel clschannel = null;
        public string ChartTypeName = "";
        public string channName = "";

        private void frmHistogram_Load(object sender, EventArgs e)
        {
            this.chart1.Series.Clear();
            this.timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Stop();
            try
            {


                List<float> displayvalue = new List<float>();
                if (Mdl_Class.onlinchannelData.Count > 0)
                {
                    object accdata = Mdl_Class.onlinchannelData.ToArray()[0];
                    int datachannelid = 0;
                    switch (Mdl_Class.LineNO)
                    {

                        case 256:
                            Acceleration_256 accdate_256 = (Acceleration_256)accdata;
                            displayvalue = accdate_256._1_3octavedB.ToList();
                            datachannelid = accdate_256.ChannelId;
                            break;
                        case 512:
                            Acceleration_512 accdate_512 = (Acceleration_512)accdata;
                            displayvalue = accdate_512._1_3octavedB.ToList();
                            datachannelid = accdate_512.ChannelId;
                            break;
                        case 1024:
                            Acceleration_1024 accdate_1024 = (Acceleration_1024)accdata;
                            displayvalue = accdate_1024._1_3octavedB.ToList();
                            datachannelid = accdate_1024.ChannelId;
                            break;
                        case 2048:
                            Acceleration_2048 accdate_2048 = (Acceleration_2048)accdata;
                            displayvalue = accdate_2048._1_3octavedB.ToList();
                            datachannelid = accdate_2048.ChannelId;
                            break;
                        case 4096:
                            Acceleration_4096 accdate_4096 = (Acceleration_4096)accdata;
                            displayvalue = accdate_4096._1_3octavedB.ToList();
                            datachannelid = accdate_4096.ChannelId;
                            break;
                        case 8192:
                            Acceleration_8192 accdate_8192 = (Acceleration_8192)accdata;
                            displayvalue = accdate_8192._1_3octavedB.ToList();
                            datachannelid = accdate_8192.ChannelId;
                            break;
                        case 16384:
                            Acceleration_16384 accdate_16384 = (Acceleration_16384)accdata;
                            displayvalue = accdate_16384._1_3octavedB.ToList();
                            datachannelid = accdate_16384.ChannelId;
                            break;
                        case 32768:
                            Acceleration_32768 accdate_32768 = (Acceleration_32768)accdata;
                            displayvalue = accdate_32768._1_3octavedB.ToList();
                            datachannelid = accdate_32768.ChannelId;
                            break;
                        case 65536:
                            Acceleration_65536 accdate_65536 = (Acceleration_65536)accdata;
                            displayvalue = accdate_65536._1_3octavedB.ToList();
                            datachannelid = accdate_65536.ChannelId;
                            break;
                        default:
                            break;
                    }
                    Mdl_Class.onlinchannelData.Clear();
                    if (datachannelid == Mdl_Class.OnLineChannelId)
                    {
                        if (displayvalue != null && displayvalue.Count > 0)
                        {
                            double[] x_value = new double[displayvalue.Count];
                            double[] y_value = new double[displayvalue.Count];
                            for (int i = 0; i < displayvalue.Count; i++)
                            {

                                x_value[i] = i + 1;

                                y_value[i] = Math.Round(Convert.ToDouble(displayvalue[i]), 3);

                            }
                            this.chart1.Series.Clear();
                            Series ser = new Series();
                            ser.ChartType = SeriesChartType.Column;
                            ser.Color = Color.Red;
                            ser.Points.DataBindXY(x_value, y_value);
                            ser.Name = clschannel.TestPointName;
                            ser.LegendText = clschannel.TestPointName;
                            this.chart1.Series.Add(ser);
                            this.lb_channelname.Text = clschannel.TestPointName;
                            this.chart1.ChartAreas[0].AxisY.Title = "单位(dB)";
                        }
                    }
                }


            }
            catch (Exception)
            {

            }



            timer1.Start();
        }



    }
}
